package com.zzccyy.jpdemo.fragment

import android.content.Intent
import android.content.pm.PackageManager
import android.view.View
import android.widget.FrameLayout
import android.widget.TextView
import com.zzccyy.jpdemo.R
import com.zzccyy.jpdemo.base.BaseLazyFragment
import com.zzccyy.jpdemo.page.FkActivity
import com.zzccyy.jpdemo.page.WebActivity

class Fragment4 : BaseLazyFragment() {
    private var l1: View? = null
    private var l2: View? = null
    private var l3: View? = null
    private var tvVersion: TextView? = null
    private var adContainer: FrameLayout? = null

    override fun setLayoutId(): Int {
        return R.layout.fr4
    }

    override fun init(view: View?) {
        l1 = view!!.findViewById(R.id.l1)
        l2 = view.findViewById(R.id.l2)
        l3 = view.findViewById(R.id.l3)
        tvVersion=view!!.findViewById(R.id.tvVersion)
        adContainer=view!!.findViewById(R.id.ad_container)
        // 获取并显示版本号
        try {
            val packageInfo = activity?.packageManager?.getPackageInfo(activity?.packageName ?: "", 0)
            val versionName = packageInfo?.versionName ?: "Unknown"
            tvVersion?.text = "Version: $versionName"
        } catch (e: PackageManager.NameNotFoundException) {
            tvVersion?.text = "Version: Unknown"
        }
    }

    override fun loadData() {
        l1!!.setOnClickListener { v: View? ->
            //隐私
            val intent = Intent(activity, WebActivity::class.java)
            intent.putExtra("type", 1)
            startActivity(intent)
        }
        l2!!.setOnClickListener { v: View? ->
            //用户
            val intent = Intent(activity, WebActivity::class.java)
            intent.putExtra("type", 0)
            startActivity(intent)
        }
        l3!!.setOnClickListener { v: View? ->
            val intent = Intent(activity, FkActivity::class.java)
            startActivity(intent)
        }
    }

    override fun getNativeView(): FrameLayout? {
        return adContainer
    }
}